package com.jin.lazytool.customevent;

import com.jin.lazytool.entity.IEvent;
import com.jin.lazytool.entity.SleepEvent;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;

public class CustomSleepEvent extends CustomEvent{

    private SleepEvent event;

    @Override
    public String getName() {
        return "等待";
    }

    {
        Tooltip.install(luaButton, new Tooltip("""
                返回对象
                {
                    exeFlag: true, // 是否执行        必须返回
                    time: 0       // 执行前等待时间    必须返回
                }"""));
    }
    @Override
    public void initAddPanel(GridPane grid) {
        grid.addRow(2,new Label("等待时间"),time);
        grid.addRow(3, luaButton, luaScript);
    }

    @Override
    public void initEditPanel(GridPane grid, IEvent event) {
        this.event = (SleepEvent)event;
        time.setValue(this.event.getTime());
        grid.addRow(2,new Label("等待时间"),time);
        grid.addRow(3, luaButton, luaScript);
    }

    @Override
    public IEvent fullAddIEvent() {
        event = new SleepEvent();
        event.setTime(time.getNullDefaultValue());
        event.setLua(luaScript.getText());
        return event;
    }

    @Override
    public void fullEditIEvent() {
        event.setTime(time.getNullDefaultValue());
        event.setLua(luaScript.getText());
    }

    @Override
    Class<? extends IEvent> eventClass() {
        return SleepEvent.class;
    }
}
